//对axios进行二次封装
import axios from "axios";
//导入nprogress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
//引入store
import store from '@/store';

let requests=axios.create({
    baseURL:'/api',
    timeout:5000,
});
//请求拦截
requests.interceptors.request.use((config)=>{
    NProgress.start();
    // console.log(store.state.detail.uuid_token);
    if(store.state.detail.uuid_token){
        config.headers.userTempId=store.state.detail.uuid_token;
        config.headers.token=localStorage.getItem('TOKEN');
    }
    return config;
})
//响应拦截
requests.interceptors.response.use((res)=>{
    NProgress.done();
    return res.data;
}),(error)=>{
    return Promise.reject(new Error("faile"));
}

export default requests;